package com.xsomnus.java_basic.jvm;

import java.time.LocalDate;

/**
 * @author 叶小夏
 * @since 2019-08-21 10:18
 * jprofile使用教程
 * https://www.cnblogs.com/jpfss/p/8488111.html
 */
public class CanReliveObj {

    public static CanReliveObj obj;

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("finalize called");
        obj = this;
    }

    @Override
    public String toString() {

        return "CanReliveObj";
    }

    public static void main(String[] args) throws InterruptedException {
        obj = new CanReliveObj();
        obj = null;
        System.gc();
        Thread.sleep(1000);
        if (obj == null) {
            System.out.println("obj 是 null");
        } else {
            System.out.println("obj 可用");
        }


        System.out.println("第二次gc");
        obj = null;

        System.gc();

        Thread.sleep(1000);
        if (obj == null) {
            System.out.println("obj 是 null");
        } else {
            System.out.println("obj 可用");
        }

    }
}
